using System.Collections.Generic;
using UnityEngine;

namespace NodeCanvas.Variables
{
	[AddComponentMenu("")]
	public class GameObjectListData : VariableData
	{
		public List<GameObject> value = new List<GameObject>();

		public override object objectValue
		{
			get
			{
				return value;
			}
			set
			{
				this.value = (List<GameObject>)value;
			}
		}

		public override object GetSerialized()
		{
			List<string> list = new List<string>();
			foreach (GameObject item in value)
			{
				GameObject gameObject = item;
				if (gameObject == null)
				{
					list.Add(null);
					continue;
				}
				string text = "/" + gameObject.name;
				while (gameObject.transform.parent != null)
				{
					gameObject = gameObject.transform.parent.gameObject;
					text = "/" + gameObject.name + text;
				}
				list.Add(text);
			}
			return list;
		}

		public override void SetSerialized(object obj)
		{
			List<string> list = new List<string>(obj as List<string>);
			foreach (string item in list)
			{
				GameObject gameObject = GameObject.Find(item);
				value.Add(gameObject);
				if (gameObject == null && !string.IsNullOrEmpty(item))
				{
					Debug.LogWarning("GameObjectListData Failed to load a GameObject in the list. GameObject was not found in scene. Path '" + item + "'");
				}
			}
		}
	}
}
